package com.yxc.elasticsearchdemo.controller;

import com.yxc.elasticsearchdemo.service.DownloadFromElasticsearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

/**
 * @author: YXC
 * @time: 2022/10/24 15:26
 **/
@RestController
@RequestMapping("/run")
public class RunController {

    @Autowired
    private DownloadFromElasticsearchService downloadFromElasticsearchService;

    @GetMapping("download")
    public String downloadFromElasticsearch() throws IOException {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startTime = LocalDateTime.parse("2022-10-15 11:00:00", formatter);
        LocalDateTime endTime = LocalDateTime.parse("2022-10-15 12:00:00", formatter);

        downloadFromElasticsearchService.downloadByParams(
                startTime.toInstant(ZoneOffset.ofHours(9)).toEpochMilli(),
                endTime.toInstant(ZoneOffset.ofHours(9)).toEpochMilli()
                );
        return "完成";
    }

}
